package com.yyh.synctool.client.tool;

import com.yyh.synctool.client.component.ThisApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * 凭证配置
 *
 * @author xuan
 * @create 2021/12/18
 */
@Component
public class CredentialConfig extends Config
{
    private static final String FILE_NAME = "credential.ini";
    private ThisApplicationContext thisApplicationContext;

    @Autowired
    public CredentialConfig(ThisApplicationContext thisApplicationContext) {
        this.thisApplicationContext = thisApplicationContext;
        super.load();
    }

    @Override
    public void load() {
        super.load();
    }

    @Override
    public void store() {
        super.store();
    }

    @Override
    protected File getFilePath() throws IOException {
        Path filePath = thisApplicationContext.getRootDir().resolve(FILE_NAME);
        if (Files.notExists(filePath)) {
            Files.createFile(filePath);
        }
        return filePath.toFile();
    }
}
